{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 导入模块并读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pregnants</th>\n",
       "      <th>Plasma_glucose_concentration</th>\n",
       "      <th>blood_pressure</th>\n",
       "      <th>Triceps_skin_fold_thickness</th>\n",
       "      <th>serum_insulin</th>\n",
       "      <th>BMI</th>\n",
       "      <th>Diabetes_pedigree_function</th>\n",
       "      <th>Age</th>\n",
       "      <th>Target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.639947</td>\n",
       "      <td>0.866045</td>\n",
       "      <td>-0.031990</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>0.166619</td>\n",
       "      <td>0.468492</td>\n",
       "      <td>1.425995</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.205066</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-0.852200</td>\n",
       "      <td>-0.365061</td>\n",
       "      <td>-0.190672</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.233880</td>\n",
       "      <td>2.016662</td>\n",
       "      <td>-0.693761</td>\n",
       "      <td>-0.012301</td>\n",
       "      <td>-0.181541</td>\n",
       "      <td>-1.332500</td>\n",
       "      <td>0.604397</td>\n",
       "      <td>-0.105584</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.844885</td>\n",
       "      <td>-1.073567</td>\n",
       "      <td>-0.528319</td>\n",
       "      <td>-0.695245</td>\n",
       "      <td>-0.540642</td>\n",
       "      <td>-0.633881</td>\n",
       "      <td>-0.920763</td>\n",
       "      <td>-1.041549</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-1.141852</td>\n",
       "      <td>0.504422</td>\n",
       "      <td>-2.679076</td>\n",
       "      <td>0.670643</td>\n",
       "      <td>0.316566</td>\n",
       "      <td>1.549303</td>\n",
       "      <td>5.484909</td>\n",
       "      <td>-0.020496</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   pregnants  Plasma_glucose_concentration  blood_pressure  \\\n",
       "0   0.639947                      0.866045       -0.031990   \n",
       "1  -0.844885                     -1.205066       -0.528319   \n",
       "2   1.233880                      2.016662       -0.693761   \n",
       "3  -0.844885                     -1.073567       -0.528319   \n",
       "4  -1.141852                      0.504422       -2.679076   \n",
       "\n",
       "   Triceps_skin_fold_thickness  serum_insulin       BMI  \\\n",
       "0                     0.670643      -0.181541  0.166619   \n",
       "1                    -0.012301      -0.181541 -0.852200   \n",
       "2                    -0.012301      -0.181541 -1.332500   \n",
       "3                    -0.695245      -0.540642 -0.633881   \n",
       "4                     0.670643       0.316566  1.549303   \n",
       "\n",
       "   Diabetes_pedigree_function       Age  Target  \n",
       "0                    0.468492  1.425995       1  \n",
       "1                   -0.365061 -0.190672       0  \n",
       "2                    0.604397 -0.105584       1  \n",
       "3                   -0.920763 -1.041549       0  \n",
       "4                    5.484909 -0.020496       1  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 首先 import 必要的模块\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "train = pd.read_csv(\"FE_pima-indians-diabetes.csv\")\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train=train['Target']\n",
    "x_train=train.drop(['Target'], axis=1)\n",
    "\n",
    "feat_names=x_train.columns\n",
    "\n",
    "#sklearn的学习器大多之一稀疏数据输入，模型训练会快很多\n",
    "#查看一个学习器是否支持稀疏数据，可以看fit函数是否支持: X: {array-like, sparse matrix}.\n",
    "#可自行用timeit比较稠密数据和稀疏数据的训练时间\n",
    "from scipy.sparse import csr_matrix\n",
    "x_train = csr_matrix(x_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 默认参数的Logistic Regression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression(solver = 'liblinear')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "logloss of each fold is:  [0.48797856 0.53011593 0.4562292  0.422546   0.48392885]\n",
      "cv logloss is:  0.47615970944434044\n",
      "accuracy of each fold is:  [-0.75974026 -0.74025974 -0.78571429 -0.79738562 -0.77124183]\n",
      "accuracy is:  -0.7708683473389355\n"
     ]
    }
   ],
   "source": [
    "# 交叉验证用于评估模型性能和进行参数调优（模型选择）\n",
    "#分类任务中交叉验证缺省是采用StratifiedKFold\n",
    "#数据集比较大，采用5折交叉验证\n",
    "from sklearn.model_selection import cross_val_score\n",
    "\n",
    "loss = cross_val_score(lr, x_train, y_train, cv=5, scoring='neg_log_loss')\n",
    "print('logloss of each fold is: ', -loss)\n",
    "print('cv logloss is: ', -loss.mean())\n",
    "\n",
    "loss = cross_val_score(lr, x_train, y_train, cv=5, scoring='accuracy')\n",
    "print('accuracy of each fold is: ', -loss)\n",
    "print('accuracy is: ', -loss.mean())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Logistic Regression + GridSearchCV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "grid_neg_log_loss.best_score_:  0.4760266756636821\n",
      "grid_neg_log_loss.best_params_:  {'C': 1, 'penalty': 'l1'}\n",
      "grid_accuracy.best_score_:  0.4760266756636821\n",
      "grid_accuracy.best_params_:  {'C': 1, 'penalty': 'l1'}\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "\n",
    "penaltys = ['l1', 'l2']\n",
    "Cs = [0.1, 1, 10, 100, 1000]\n",
    "tuned_parameters = dict(penalty = penaltys, C = Cs)\n",
    "\n",
    "lr_penalty = LogisticRegression(solver='liblinear')\n",
    "grid_neg_log_loss = GridSearchCV(lr_penalty, tuned_parameters, cv=5, scoring='neg_log_loss', n_jobs=4)\n",
    "grid_neg_log_loss.fit(x_train, y_train)\n",
    "\n",
    "grid_accuracy = GridSearchCV(lr_penalty, tuned_parameters, cv=5, scoring='accuracy', n_jobs=4)\n",
    "grid_accuracy.fit(x_train, y_train)\n",
    "\n",
    "print('grid_neg_log_loss.best_score_: ', -grid_neg_log_loss.best_score_)\n",
    "print('grid_neg_log_loss.best_params_: ', grid_neg_log_loss.best_params_)\n",
    "\n",
    "print('grid_accuracy.best_score_: ', -grid_neg_log_loss.best_score_)\n",
    "print('grid_accuracy.best_params_: ', grid_neg_log_loss.best_params_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3dfZRV9X3v8ffnnBkYkDEQZpIgYEEvtgGjGMeH1IdrNEZiLCRVG/Nsm4Zm3bBsc5O0mPaaK3alqemtaVe5NxKrMU0aNNq0EySSxMaYpFUZCShIVGSZOoJxwMiDAvNwvvePvWc4HPbMnIHZc2D4vNY6a/bD77fP92yY85n9rIjAzMysUqHWBZiZ2ZHJAWFmZpkcEGZmlskBYWZmmRwQZmaWqa7WBQyXpqammDFjRq3LMDM7qjz22GPbIqI5a96oCYgZM2bQ1tZW6zLMzI4qkn7Z3zzvYjIzs0wOCDMzy+SAMDOzTKPmGISZWbmuri7a29vZu3dvrUs5IjQ0NDBt2jTq6+ur7uOAMLNRqb29ncbGRmbMmIGkWpdTUxHB9u3baW9vZ+bMmVX38y4mMxuV9u7dy+TJk4/5cACQxOTJk4e8NeWAMLNRy+Gw36GsCweEmVnqfbf+J++79T9rXcYRwwFhZkeUDV84nw1fOL/WZQyLCRMm9A3PmzePiRMncsUVV2S2/eQnP8ncuXOZPXs248aNY+7cucydO5d77rlnwPfYs/UX7Nn6i77xNWvWcP/99w9L/T5IbZaz3i+7OZ/7aY0rsVr67Gc/y2uvvcatt96aOX/p0qUAPPfcc1xxxRWsXbv2kN5nzZo1rF+/nnnz5h1yrb28BWFmNgIuueQSGhsbD6nvM888w2WXXcaZZ57JhRdeyNNPPw3A8uXLaXn773DOO97D29/+dvbs2cOSJUv45je/WdXWx2C8BWFDd8e7k5+/f19t6zCr0o3f3cCTW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AucDjQBqyU9RHLbkxnAW0juxLsRuD3tcx7JVc0Ac4C1kdx8Lct64KxcKjerkrcgzA7N+SR3jO2JiF8BPyb5Qj8f+HZElCLiRZJbffSaAnRUs/A0ODolNQ5z3WZVc0CYHZr+HsIy0MNZ9pDcKweS+/icLmmg38GxwN5DqM1sWDggzA7NQ8D70ge4NJM81vNR4KckDysqSHojyaMpe20E/htAJM/uaANuLLsr6CxJC9LhyUBHRHSN1Acyq+SAMDs03yG5q+Y64N+BP013Kd1LcsfU9cCtJE8i25H2uY8DA+MPSR4ctUnSEyTPruh91sHbgZX5fgSzgflurmbDTNKESB0uf6kAAABtSURBVJ40Nplkq+K8iHgxvYf/j9Lx/g5O9y7jX4DrY/DnppvlxmcxmQ2/FemDXcYAN6VbFkTEHkmfJ3lu8H/11zl9ENK/Ohys1rwFYWZmmXwMwszMMjkgzMwskwPCzMwyOSDMzCyTA8LMzDL9f0k8E8AzeKH0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线 neg_log_loss\n",
    "test_means = grid_neg_log_loss.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid_neg_log_loss.cv_results_[ 'std_test_score' ]\n",
    "#train_means = grid_neg_log_loss.cv_results_[ 'mean_train_score' ]\n",
    "#train_stds = grid_neg_log_loss.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "#train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "#train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    #plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'logloss' )\n",
    "plt.savefig('LogisticGridSearchCV_neg.png' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEGCAYAAABLgMOSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deXxV9ZnH8c+TkBC2soNhM4rgAkiQqKiIslipWoEKiq11qUh3W53q2OlUR9txrM7YjjNtFZ1S7DiKtUWoGyCy2FagKaIEURCKikShYREMIYE888c5wRvMcnKSe28g3/frdV/3LL9z7nMPSb6c7XfM3REREWmojHQXICIiRyYFiIiIxKIAERGRWBQgIiISiwJERERiaZXuAlKpW7dunpeXl+4yRESOKH/961//7u7dD5/eogIkLy+PwsLCdJchInJEMbN3apquQ1giIhKLAkRERGJRgIiISCwt6hyIiEiViooKtmzZQllZWbpLaTZycnLo06cPWVlZkdorQESkRdqyZQsdOnQgLy8PM0t3OWnn7pSUlLBlyxaOO+64SMvoEJaItEhlZWV07dpV4REyM7p27dqgPTIFiIi0WAqP6hq6PRQgIiIRXfHQK1zx0CvpLqPZUIBEoB8aEUmG9u3bHxoeP348nTp14pJLLqmx7Te/+U3y8/M55ZRTaNOmDfn5+eTn5/PUU0816DNXrVrFCy+80Ki6q+gkuohIM3DLLbdQ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Hf3ilR9IZHDKUBEkmMOQa+orwEvAbeGh6x+R9DjbRHwEMGT7HaHyzxL9UCZRvBgsbfNbA3Bc0uqnnUxGnguuV9BpG7qjVckxcysvQdPqutKsFdyjrt/ED7DYXE4XtvJ86p1/B74vru/lYKSRWqkq7BEUu+Z8ME/2cCPwj0T3H2fmd1B8Nzqd2tbOHxI1tMKD0k37YGIiEgsOgciIiKxKEBERCQWBYiIiMSiABERkVgUICIiEsv/AytrKpo7SVbdAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot CV误差曲线 accuracy\n",
    "test_means = grid_accuracy.cv_results_[ 'mean_test_score' ]\n",
    "test_stds = grid_accuracy.cv_results_[ 'std_test_score' ]\n",
    "#train_means = grid_neg_log_loss.cv_results_[ 'mean_train_score' ]\n",
    "#train_stds = grid_neg_log_loss.cv_results_[ 'std_train_score' ]\n",
    "\n",
    "# plot results\n",
    "n_Cs = len(Cs)\n",
    "number_penaltys = len(penaltys)\n",
    "test_scores = np.array(test_means).reshape(n_Cs,number_penaltys)\n",
    "#train_scores = np.array(train_means).reshape(n_Cs,number_penaltys)\n",
    "test_stds = np.array(test_stds).reshape(n_Cs,number_penaltys)\n",
    "#train_stds = np.array(train_stds).reshape(n_Cs,number_penaltys)\n",
    "\n",
    "x_axis = np.log10(Cs)\n",
    "for i, value in enumerate(penaltys):\n",
    "    #pyplot.plot(log(Cs), test_scores[i], label= 'penalty:'   + str(value))\n",
    "    plt.errorbar(x_axis, -test_scores[:,i], yerr=test_stds[:,i] ,label = penaltys[i] +' Test')\n",
    "    #plt.errorbar(x_axis, -train_scores[:,i], yerr=train_stds[:,i] ,label = penaltys[i] +' Train')\n",
    "    \n",
    "plt.legend()\n",
    "plt.xlabel( 'log(C)' )                                                                                                      \n",
    "plt.ylabel( 'accuracy' )\n",
    "plt.savefig('LogisticGridSearchCV_accurancy.png' )\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
